<template>
  <div class="HandoverList">
    <!-- 筛选条件 -->
    <HandoverListScreen @changeParams="changeParams" />
    <!-- item -->
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <div v-if="list.length > 0">
        <HandoverListItem
          v-for="(item, index) in list"
          :key="index"
          :data="item"
        />
      </div>
      <van-empty v-else />
    </van-list>
  </div>
</template>

<script>
import Vue from "vue";
import { getdeliveryHandoverList } from "./../services/api";
import HandoverListScreen from "@/components/HandoverListScreen.vue";
import HandoverListItem from "@/components/HandoverListItem.vue";
import { List, Empty } from "vant";

Vue.use(Empty);
Vue.use(List);
export default {
  data() {
    return {
      params: {
        masterWaybillLike: "",
        deliverCargoNoLike: "",
        pageNum: 1,
        pageSize: 20,
        loadingService: "",
      },
      list: [],
      loading: false,
      finished: false,
    };
  },
  mounted() {
    window["reload"] = () => {
      this.list = [];
      this.loading = false;
      this.finished = false;
      this.params = {
        ...this.params,
        pageNum: 1,
        pageSize: 20,
      };
    };
  },
  methods: {
    onLoad() {
      getdeliveryHandoverList(this.params).then((res) => {
        if (res) {
          // 加载状态结束
          this.loading = false;
          if (this.params.pageNum == 1) {
            this.list = res.list;
          } else {
            this.list = this.list.concat(res.list);
          }
          this.params.pageNum += 1;
          if (res.list.length < 20) {
            this.finished = true;
          }
        }
      });
    },
    // 子组件传值
    changeParams(e) {
      this.params = {
        ...e,
        loadingService: e.loadingService ? 1 : "",
        pageNum: 1,
        pageSize: 20,
      };
      this.finished = false;
    },
  },
  components: {
    HandoverListScreen,
    HandoverListItem,
  },
};
</script>

<style lang="scss" scoped>
</style>